package com.joney.mq.activemq;

import com.joney.mq.pojo.Content;
import org.apache.activemq.command.ActiveMQObjectMessage;
import org.springframework.beans.BeanUtils;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.ObjectMessage;


/**
 * @author wangxianchen
 * @create 2018-03-06
 * @desc
 */

@Component
public class Consumer {
    // 使用JmsListener配置消费者监听的队列，其中text是接收到的消息

    @JmsListener(destination = "direct.queue",containerFactory = "jmsListenerContainerQueue")
    public void r1(Message message) {
        Content content;
        if(message instanceof ActiveMQObjectMessage){
            ActiveMQObjectMessage objectMessage=(ActiveMQObjectMessage) message;
            try {
                content = (Content) objectMessage.getObject();
                System.out.println(content);
            } catch (JMSException e) {
                e.printStackTrace();
            }
        }
        System.out.println("r1 收到的报文为:"+message.toString());
    }

    @JmsListener(destination = "topic.queue",containerFactory = "jmsListenerContainerTopic")
    public void r2(String text) {
        System.out.println("r2 收到的报文为:"+text);
    }

    @JmsListener(destination = "topic.queue",containerFactory = "jmsListenerContainerTopic")
    public void r3(String text) {
        System.out.println("r3 收到的报文为:"+text);
    }
}